<template>
  <div>
    <el-row >
      <el-col :span="5">
      </el-col>
      <el-col :span="15">
        <div class="grid-content bg-purple">
          <el-form-item prop="visitPlace"  style="margin-left: 70px" label="跟进地址">
            <el-input
              style="width: 145%;margin-left: 16px"
              v-model="provincesModel"
              clearable
              placeholder=""
            />
          </el-form-item>
        </div>
      </el-col>
    </el-row>
    </div>
</template>
<script>
import {ajax} from "@/store/yg/common/utils";
import * as constant from "@/store/yg/common/constant";

export default {
  props: ["data"],
  data() {
    return {
      provincesModel:"",
      customerId:this.$store.state.edit.row.customerId
    };
  },
  mounted(){
    console.log(this.$store.state.edit.row)
    if(this.$route.query.pid!=null){
    if(!this.$store.state.edit.row.id){
      this.editData();
    }else{
      if (this.$store.state.edit.row.visitPlace) {
        console.log(this.$store.state.edit.row.visitPlace)
        this.provincesModel = this.$store.state.edit.row.visitPlace;
      }
    }
    }else{
      if (this.$store.state.edit.row.visitPlace) {
        console.log(this.$store.state.edit.row.visitPlace)
        this.provincesModel = this.$store.state.edit.row.visitPlace;
      }
    }
  },
  watch: {
    'provincesModel': {
      handler(nVal) {
        this.$store.state.edit.row.visitPlace = nVal;
      }
    },
    '$store.state.edit.row.customerId': {
      handler(nVal) {
        console.log("监控")
        this.init();
      }
    },
  },

  methods:{
    async editData(){
      const attrs = {
        class: "com.tofba.app.client.customer.CustomerInfoClient"
      };
      let res = await ajax("queryById", {
        id: this.$route.query.pid
      },attrs);
      if (res !== null) {
        this.provincesModel=res.state+res.city+res.area+res.street+res.businessAddress;
        // console.log(this.$store.state.edit.row.visitPlace)

      }
    },
    async init() {
      const attrs = {
        class: "com.tofba.app.client.customer.CustomerInfoClient"
      };
      console.log("customerId",this.customerId)
      let res = await ajax("queryById", {
        id: this.customerId
      },attrs);
      if (res&&res.state) {
        this.provincesModel=res.state+res.city+res.area+res.street+res.businessAddress;
        // console.log(this.$store.state.edit.row.visitPlace)

      }
    },
    sleep(numberMillis) {
     var now = new Date();
     var exitTime = now.getTime() + numberMillis;
    while (true) {
       now = new Date();
       if (now.getTime() > exitTime)
      return;
      }
    }
  }

}
</script>

<style scoped>

</style>
